<template>
	<div class="box">
		<div class="null-page" v-show="yes"></div>
		
		<el-card class="box-card order-list">
			<div slot="header" class="clearfix"><span>自提点列表</span></div>

			<el-tabs v-model="orderStatus" @tab-click="handleClick">
				<el-tab-pane label="全部" name="all"></el-tab-pane>
				<el-tab-pane label="待配送" name="0"></el-tab-pane>
				<el-tab-pane label="配送中" name="1"></el-tab-pane>
				<el-tab-pane label="已送达" name="2"></el-tab-pane>
			</el-tabs>

			<div v-loading="loading">
				<nav>
					<li>创建时间</li>
					<li>订单号</li>
					<li>联系方式</li>
					<li>订单数</li>
					<li>状态</li>
                    <li>配送详情</li>
                    <li>配送商家</li>
				</nav>

				<div class="list" v-if="orderList.length > 0">
                    <ul v-for="(orderItem, orderIndex) in orderList" :key="orderIndex">
							<li>
                                <span class="create-time">{{ $util.timeStampTurnTime(orderItem.create_time) }}</span>
							</li>
							<li>
								<span class="order-no">{{ orderItem.delivery_no }}</span>
							</li>
							<li>
								 <span class="order-no">{{ orderItem.site_info.telephone }}111</span>
							</li>
							<li>
								<span class="order-no">{{ orderItem.order_count }}</span>
							</li>
                            <li>
								<!-- v-if="orderItem.status == 1" -->
								<span class="order-no" v-if="orderItem.status == 1">配货中<span><el-link :underline="false" @click="is_send(orderItem)">送达</el-link></span></span>
                                <span class="order-no" v-if="orderItem.status == 0">待配货</span>
                                <span class="order-no" v-if="orderItem.status == 2">已送达</span>
							</li>
                            <li>
								<span><el-link :underline="false" @click="orderDetail(orderItem.delivery_id)">配送详情</el-link></span>
							</li>
                            <li>
								<router-link :to="'/shop-' + orderItem.site_info.site_id" target="_blank">{{ orderItem.site_info.site_name }}</router-link>
							</li>
						</ul>
				</div>
				<div v-else-if="!loading && orderList.length == 0" class="empty-wrap">暂无相关订单</div>
			</div>
			<div class="pager">
				<el-pagination 
					background 
					:pager-count="5" 
					:total="total" 
					prev-text="上一页" 
					next-text="下一页" 
					:current-page.sync="currentPage" 
					:page-size.sync="pageSize" 
					@size-change="handlePageSizeChange" 
					@current-change="handleCurrentPageChange" 
					hide-on-single-page
				></el-pagination>
			</div>
		</el-card>
	</div>
</template>

<script>
import { mapGetters } from 'vuex';
import { pickpoint_list, surePickup } from '@/api/member/pickup';
import orderMethod from '@/utils/orderMethod';
export default {
	name: 'pickup_list',
	components: {},
	data: () => {
		return {
			orderStatus: 'all',
			loading: true,
			orderList: [],
			currentPage: 1,
			pageSize: 10,
			total: 0,
			yes: true,
            status: 0,
		};
	},
	mixins: [orderMethod],
	created() {
		this.orderStatus = this.$route.query.status || 'all';
		this.getOrderList();
	},
	computed: {
		...mapGetters(['defaultGoodsImage'])
	},
	mounted() {
		let self = this;
		setTimeout(function() {
			self.yes = false
		}, 300)
	},
	methods: {
        is_send(id) {
			this.$confirm('确定要提货吗?', '一键提货', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                }).then(() => {

					surePickup({
						delivery_id: id,
					})
						.then(res => {
							if(res.code == 0) {
								this.$message({
									type: 'success',
									message: '成功!'
								});
								this.refresh();
							}
						})
						.catch(err => {
							this.$message({
								type: 'info',
								message: '送达失败，请重新操作!'
							});  
						})                    
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消'
                    });          
                });
        },
		handleClick(tab, event) {
			this.currentPage = 1;
			this.orderStatus = tab.name;
			this.refresh();
		},
		getOrderList() {
            if(this.orderStatus == 'all') {
                //this.orderStatus = '';
                this.status = '';
            }
            if(this.orderStatus !== '') {
                //this.orderStatus = parseInt(this.orderStatus);
                this.status = parseInt(this.orderStatus)
            }
			pickpoint_list({
				page: this.currentPage,
				page_size: this.pageSize,
				status: this.status
			})
				.then(res => {
					let list = [];
					if (res.code == 0 && res.data) {
						list = res.data.list;
						this.total = res.data.count;
					}
					this.orderList = list;
					this.loading = false;
				})
				.catch(res => {
					this.loading = false;
				});
		},
		handlePageSizeChange(size) {
			this.pageSize = size;
			this.refresh();
		},
		handleCurrentPageChange(page) {
			this.currentPage = page;
			this.refresh();
		},
		refresh() {
			this.loading = true;
			this.getOrderList();
		},
		operation(action, orderData) {
			let index = this.status;
			switch (action) {
				case 'orderPay': // 支付
					this.orderPay(orderData);
					break;
				case 'orderClose': //关闭
					this.orderClose(orderData.order_id, () => {
						this.refresh();
					});
					break;
				case 'memberTakeDelivery': //收货
					this.orderDelivery(orderData.order_id, () => {
						this.refresh();
					});
					break;
				case 'trace': //查看物流
					this.$router.push({ path: '/member/logistics', query: { order_id: orderData.order_id } });
					break;
				case 'memberOrderEvaluation': //评价
					this.$router.pushToTab({ path: '/evaluate', query: { order_id: orderData.order_id } });
					break;
			}
		},
		orderDetail(data) {
            this.$router.push({ path: '/member/pickup_detail?delivery_id='+data });
		},
		imageError(orderIndex, goodsIndex) {
			this.orderList[orderIndex].order_goods[goodsIndex].sku_image = this.defaultGoodsImage;
		}
	}
};
</script>
<style lang="scss" scoped>
.box {
	width: 100%;
	position: relative;
}

.null-page {
	width: 100%;
	height: 730px;
	background-color: #FFFFFF;
	position: absolute;
	top: 0;
	left: 0;
	z-index: 9;
}

.order-list {
	nav {
		overflow: hidden;
		padding: 10px 0;
		background: #fff;
		margin-bottom: 10px;
		border-bottom: 1px solid #eeeeee;
		li {
			float: left;
			&:nth-child(1) {
				width: 15%;
			}
			&:nth-child(2) {
				width: 15%;
			}
			&:nth-child(3) {
				width: 15%;
			}
			&:nth-child(4) {
				width: 15%;
			}
			&:nth-child(5) {
				width: 12%;
			}
			&:nth-child(6) {
				width: 15%;
			}
		}
	}
	.list {
		.item {
			margin-bottom: 20px;
			border: 1px solid #eeeeee;
			border-top: 0;
			.head {
				padding: 8px 0px;
				background: #f7f7f7;
				font-size: 12px;

                span{
                    display: inline-block;
                    width:15%;
                }

				.create-time {
					//margin-right: 10px;
				}

				border-bottom: 1px solid #eeeeee;
				a {
					//margin: 0 10px 0 20px;
				}

				.order-type {
					//margin-left: 30px;
				}
			}
		}
		ul {
			background-color: #fff;
			padding: 10px;
            margin: 20px 0;
			overflow: hidden;
			li {
				float: left;
				line-height: 60px;
				&:nth-child(1) {
					width: 15%;
					line-height: 30px;
					.img-wrap {
						width: 60px;
						height: 60px;
						float: left;
						margin-right: 10px;
						cursor: pointer;
					}
					.info-wrap {
						margin-left: 70px;
						h5 {
							font-weight: normal;
							font-size: $ns-font-size-base;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							overflow: hidden;
							margin-right: 10px;
							display: inline-block;
							cursor: pointer;
							&:hover {
								color: $base-color;
							}
						}
						span {
							font-size: $ns-font-size-sm;
							color: #9a9a9a;
						}
					}
				}
				&:nth-child(2) {
					width: 15%;
                    line-height: 30px;
				}
				&:nth-child(3) {
					width: 15%;
                    line-height: 30px;
				}
				&:nth-child(4) {
					width: 15%;
                    line-height: 30px;
				}
				&:nth-child(5) {
					width: 12%;
					line-height: 30px;
					a {
						display: block;
					}
				}
				&:nth-child(6) {
					width: 10%;
					line-height: 30px;
					button {
						margin-left: 0;
						margin-bottom: 10px;
						&:last-child {
							margin-bottom: 0;
						}
					}
				}
                &:nth-child(7) {
					width: 15%;
					line-height: 30px;
					button {
						margin-left: 0;
						margin-bottom: 10px;
						&:last-child {
							margin-bottom: 0;
						}
					}
				}
			}
		}
	}
	.empty-wrap {
		text-align: center;
		padding: 10px;
	}
}
</style>
